﻿$("#exampleAccordion>li:nth-child(7) a").removeClass("collapsed");
$("#exampleAccordion>li:nth-child(7) ul").addClass("show");
$("#exampleAccordion>li:nth-child(7) ul>li:nth-child(2)").addClass("active");

var setting = {
	async: {
		enable: true,
		url: "/Member/LoadTreeMUP",
		type: "post",
		autoParam: ["id"],
		//otherParam: {  },
		//dataFilter: filter
	},
	view: {
		selectedMulti: false,
		showLine: true
	},
	callback: {
		onClick: onclick,
		onAsyncError: moneySuperiorAsyncError,
		//onAsyncSuccess: moneySuperiorAsyncError
	}
};

var settings = {
	async: {
		enable: true,
		url: "/Member/LoadTreeEUP",
		type: "post",
		autoParam: ["id"],
	},
	view: {
		selectedMulti: false,
        showLine: true
	},
	callback: {
		onClick: onclick,
		onAsyncError: expSuperiorAsyncError,
	}
};

var settingCompany = {
	async: {
		enable: true,
		url: "/Member/LoadTreeCompany",
		type: "post",
		autoParam: ["id"],
	},
	view: {
		selectedMulti: false,
        showLine: true
	},
	callback: {
		onClick: onclick,
		onAsyncError: expSuperiorAsyncError,
	}
}

//经验上级的请求错误回调
function moneySuperiorAsyncError() {
	layer.msg("请求失败")
}


//经验上级的请求错误回调
function expSuperiorAsyncError() {
	layer.msg("请求失败")
}
var ID = "";
//单击回调
function onclick(event, treeId, treeNode, clickFlag) {
    console.log(treeId)
	var type = getCookie('jiangjin').split("&")[3].split("=")[1];

	var str1 = '';
	var str2 = '';
	var str3 = '';

	if (type == '07332506fa00992798c91411c89023a8') {
		str1 = '<a class="pull-right text-danger" href="javascript:void(0)" onclick="AmendSuperior(this,1)">修改</a>';
		str2 = '<a class="pull-right text-danger" href="javascript:void(0)" onclick="AmendSuperior(this,2)">修改</a>';
		str3 = '<a class="pull-right text-danger" href="javascript:void(0)" onclick="pauseDate(this)">修改</a>'
	}
	$.post('/Member/Detail', { id: treeNode.id }, function (data, textStatus, xhr) {
		ID = data.Id;
		var html = "";
		html += '<div class="card-header"><span class="text-danger">' + data.Data.Name + '</span>的资料卡</div>';
		html += '<div class="card-body">';
		html += '<table class="table table-bordered mb-0">';
		html += '<tbody>';
		html += '<tr>';
		html += '<td class="text-right">';
		html += '<strong>用户编号:</strong>';
		html += '</td>';
		html += '<td class="text-muted">' + data.Data.NO + '</td>';
		html += '</tr>';
		html += '<tr>';
		html += '<td class="text-right"><strong>用户名:</strong></td>';
		html += '<td class="text-muted">' + data.Data.Name + '</td>';
		html += '</tr>';
		html += '<tr>';
		html += '<td class="text-right"><strong>身份证姓名:</strong></td>';
		html += '<td class="text-muted">' + data.Data.UserName + '</td>';
		html += '</tr>';
		html += '<tr>';
		html += '<td class="text-right"><strong>用户等级:</strong></td>';
		html += '<td class="text-muted Grade"><span>' + data.Level + '</span></td>';
		html += '</tr>';
		html += '<tr>';
		html += '<td class="text-right"><strong>安置人:</strong></td>';
		html += '<td class="text-muted"><span>' + data.EUP + '</span>' + str1 + '</td>';
		html += '</tr>';
		html += '<tr>';
		html += '<td class="text-right"><strong>推荐人:</strong></td>';
		html += '<td class="text-muted"><span>' + data.MUP + '</span>' + str2 + '</td>';
		html += '</tr>';

		if (type == '07332506fa00992798c91411c89023a8') {
			html += '<tr>';
			html += '<td class="text-right"><strong>余额:</strong></td>';
			html += '<td class="text-muted">' + data.Data.Money + '<a class="pull-right text-danger" href="javascript:void(0)" onclick="pauseMoney(this)">' + (data.Data.IsMStop ? "开通" : "暂停") + '</a></td>';
			html += '</tr>';
			html += '<tr>';
			html += '<td class="text-right"><strong>冻结资金:</strong></td>';
			html += '<td class="text-muted">' + data.Data.Freeze + '</td>';
			html += '</tr>';
            if (treeId != "Company") {
                html += '<tr>';
                html += '<td class="text-right"><strong>PV值:</strong></td>';
                html += '<td class="text-muted"><span>' + data.Data.EXP + '</span><a class="pull-right ml-2 text-danger" href="javascript:void(0)" onclick="addPV(this)">个人增加</a><a class="pull-right ml-2 text-danger" href="javascript:void(0)" onclick="addPVs(this)">整体增加</a><a class="pull-right text-danger" href="javascript:void(0)" onclick="pausePV(this)">' + (data.Data.IsEStop ? "开通" : "暂停") + '</a></td>';
                html += '</tr>';
                html += '<tr>';
                html += '<td class="text-right"><strong>账号绑定:</strong></td>';
                html += '<td class="text-muted"><div class="row"><div class="col-md-10"><input type="text" id="BindAccount" class="form-control" disabled placeholder="请输入用户编号,多个以&quot;|&quot;分割" value="' + data.Bind + '"></div><div class="col-md-2" style="line-height:2.4em"><a class="pull-right ml-2 text-danger" href="javascript:void(0)" onclick="BindAccount(this)">修改</a></div></div></td>';
                html += '</tr>';
            }
			html += '<tr>';
			html += '<td class="text-right"><strong>银行名称:</strong></td>';
			html += '<td class="text-muted">' + (data.Data.BankName == null ? "无" : data.Data.BankName) + '</td>';
			html += '</tr>';
			html += '<tr>';
			html += '<td class="text-right"><strong>银行卡号:</strong></td>';
			html += '<td class="text-muted">' + (data.Data.BankNO == null ? "无" : data.Data.BankNO) + '</td>';
			html += '</tr>';
			html += '<tr>';
		}
		html += '<td class="text-right"><strong>注册时间:</strong></td>';
		html += '<td class="text-muted"><span>' + data.AddDT + '</span>' + str3 + '</td>';
		html += '</tr>';
		html += '</tbody>';
		html += '</table>';
		html += '</div>';
		$("#user-Msg").html(html);
        $("#user-Msg table tr td:first-child").css({
            'width': '40%',
            "vertical-align": "middle"
        });
        $("#user-Msg table tr td:last-child").css({
            'width':'60%'
        })
	});

}



$(document).ready(function () {
	$.fn.zTree.init($("#moneySuperior"), setting);
	$.fn.zTree.init($("#expSuperior"), settings);
	$.fn.zTree.init($("#Company"), settingCompany);
});

// 个人增加PV值
function addPV(t) {
	layer.prompt({ title: '输入个人增加的PV值(数字类型)', formType: 0 }, function (number, index) {
        layer.close(index);
        var index = layer.load(1, { shade: [0.6, '#636363'] });
		$.post('/Member/AddEX', { userId: ID, EX: number }, function (data, textStatus, xhr) {
			$(t).siblings('span').text(data.Title);
            $(".Grade span").text(data.Grade);
            layer.close(index);
            layer.msg(data.Msg);
		});
	});
}

// 整体增加PV值
function addPVs(t) {
	layer.prompt({ title: '输入整体增加的PV值(数字类型)', formType: 0 }, function (number, index) {
        layer.close(index);
        var index = layer.load(1, { shade: [0.6, '#636363'] });
		$.post('/Member/AddEXs', { userId: ID, EX: number }, function (data, textStatus, xhr) {
			$(t).siblings('span').text(data.Title);
            $(".Grade span").text(data.Grade);
            layer.close(index);
			layer.msg(data.Msg);
		});
	});
}
//暂停PV值
function pausePV(t) {
    var index = layer.load(1, { shade: [0.6, '#636363'] });
	$.post('/Member/StopEXP', { userId: ID }, function (data, textStatus, xhr) {
		layer.msg(data.Msg)
        $(t).text(data.Title)
        layer.close(index);
	});
}
//暂停金钱
function pauseMoney(t) {
    var index = layer.load(1, { shade: [0.6, '#636363'] });
	$.post('/Member/StopMoney', { userId: ID }, function (data, textStatus, xhr) {
		layer.msg(data.Msg)
        $(t).text(data.Title)
        layer.close(index);
	});
}
//修改时间
function pauseDate(t) {
	layer.open({
		type: 1,
		content: '<div class="p-3"><input class="form-control" id="date" type="date"></div>', //这里content是一个普通的String
		title: "修改时间",
		btn: ['确定', '取消'],
        yes: function () {
            var index = layer.load(1, { shade: [0.6, '#636363'] });
			$.post('/Member/EditAddDT', { userId: ID, dt: $("#date").val() }, function (data, textStatus, xhr) {
				$(t).siblings('span').text(data.Title)
                layer.closeAll('page');
                layer.close(index);
                layer.msg(data.Msg)
			});
		}
	});
}
//修改安置人/推荐人
function AmendSuperior(t, type) {
    layer.prompt({ title: '请输入你要修改的编号', formType: 0 }, function (text, index) {
        if (text != undefined || text != "") {
            var indexs = layer.load(1, { shade: [0.6, '#636363'] });
			$.post('/Member/EditUp', { id: ID, no: text, type: type }, function (data, textStatus, xhr) {
				layer.msg(data.Msg);
                $(t).siblings('span').text(text);
                layer.close(indexs);
			});
		} else {
			layer.msg("内容不能为空");
        }
        layer.close(index);
	});
}
//绑定账号
function BindAccount(t) {
    if ($("#BindAccount").prop("disabled")) {
        $('#BindAccount').removeAttr("disabled");
        //console.log("不能点击")
    } else {
        //console.log("能点击");
        var arr = [];
        arr = $("#BindAccount").val().split("|");
        layer.confirm('确定要绑定吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            var index = layer.load(1, { shade: [0.6, '#636363'] });
            $.post("/Member/EditBind", { userId: ID, arr: arr }, function (data) {
                $('#BindAccount').attr("disabled", true);
                layer.close(index);
                layer.closeAll('page');
                layer.msg(data.Msg);
            })
        });
        
    }
}